package com.bruce.httpclientserver.controller;

import com.bruce.httpclient.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author Bruce
 */
@Controller
public class TestController {
    //请求体传递请求参数
    @RequestMapping(value = "/bodyParams", produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    @CrossOrigin
    public String bodyParams(@RequestBody List<User> users) {
        System.out.println(users);
        return users.toString();
    }


    @RequestMapping(value = "/params", produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public String params(String name, String password){
        System.out.println("username - " + name + "  password - " + password);
        return "{\"msg\":\"登录成功\", \"user\":{\"username\":" + name + ",\"password\":"+password+"}";
    }


    @RequestMapping(value = "/test",produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public String test(){
        return "{\"msg\":\"处理返回\"}";
    }
}
